package com.epam.qanda.web.servlet.moderator;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.qanda.db.model.Question;
import com.epam.qanda.db.service.QuestionService;

public class ChangeQuestionCategoryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer categoryId = Integer.parseInt(request.getParameter("category"));
		Integer userId = Integer.parseInt(request.getParameter("qID"));
		Question question = new QuestionService().read(userId);
		question.setCategoryId(categoryId);
		new QuestionService().update(question);
		response.sendRedirect(request.getHeader("Referer"));
	}

}
